package com.changgou.webseckill.controller;

import com.changgou.entity.Result;
import com.changgou.seckill.feign.SeckillFeign;
import com.changgou.seckill.pojo.SeckillGoods;
import com.changgou.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: 大佬味的小男孩
 * @date: 2020-08-07 16:26
 **/
@Controller
@RequestMapping("/wseckillgoods/")
public class SecKillGoodsController {

    @Autowired
    private SeckillFeign seckillFeign;

    /**
     * @param
     * @return java.lang.String
     * @description: 跳转秒杀首页
     * @author 大佬味的小男孩
     * @date 2020/08/07 16:29
     */
    @RequestMapping("/toIndex")
    public String toIndex() {
        return "seckill-index";
    }


    /**
     * @param
     * @return java.util.List<java.lang.String>
     * @description: 获取秒杀时间段 集合信息
     * @author 大佬味的小男孩
     * @date 2020/08/07 16:30
     */
    @RequestMapping("/timeMenus")
    @ResponseBody
    public List<String> dateMenus() {
        List<Date> dateMenus = DateUtil.getDateMenus();
        List<String> result = new ArrayList<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for (Date dateMenu : dateMenus) {
            String format = simpleDateFormat.format(dateMenu);
            result.add(format);
        }
        return result;
    }


    /**
     * @param time
     * @return com.changgou.entity.Result<java.util.List < com.changgou.seckill.pojo.SeckillGoods>>
     * @description: 获取秒杀商品列表
     * @author 大佬味的小男孩
     * @date 2020/08/07 18:54
     */
    @RequestMapping("/list")
    @ResponseBody
    public Result<List<SeckillGoods>> list(String time) {
        Result<List<SeckillGoods>> list = seckillFeign.list(DateUtil.formatStr(time));
        return list;
    }
}
